from pdf2image import convert_from_path
import zipfile
import os

def pdf_to_images(pdf_path, output_file):
    # 将PDF转换为图片列表
    images = convert_from_path(
      pdf_path = pdf_path
    )
    
    for i, image in enumerate(images):
        # 将图片保存为文件
        image_path = f'temp/page_{i+1}.png'
        image.save(image_path, 'PNG')

    with zipfile.ZipFile(output_file, 'w') as zipf:
        for i in range(len(images)):
            zipf.write(f'temp/page_{i+1}.png')
            os.remove(f'temp/page_{i+1}.png')